#include <iostream>
#include <vector>
#include <algorithm>

using std::cout;
using std::endl;
using std::vector;
using std::remove_if;
using std::for_each;

bool func(int value)
{
    return value > 5;
}

void test()
{
    vector<int> vec = {1, 3, 6, 7, 9, 4, 6};
    for_each(vec.begin(), vec.end(), [](int &value){
             cout << value << "  ";
             });
    cout << endl;

    cout << endl << "测试remove_if操作" << endl;
    //remove_if函数往往需要配合容器的erase操作，才能将满足条件
    //元素达到真正的删除，通用性的表现（泛型编程的思想）
    auto it = remove_if(vec.begin(), vec.end(), [](int value){
                        return value > 5;
                        });

    /* auto it = remove_if(vec.begin(), vec.end(), func); */
    vec.erase(it, vec.end());
    for_each(vec.begin(), vec.end(), [](int &value){
             cout << value << "  ";
             });
    cout << endl;
}

int main(int argc, char *argv[])
{
    test();
    return 0;
}

